package features.advance.jdk.design;

import java.util.HashSet;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;

/**
 * @author LIN
 * @date 2021-08-19
 */
public class ConcreteObserver implements Observer {
    private  int count = 0;

    private Set<String> valiables = new HashSet<>(16);

    public ConcreteObserver() {

    }

    public ConcreteObserver(Set<String> valiables) {
        this.valiables = valiables;
        this.count = valiables.size();
    }

    @Override
    public void update(Observable o, Object arg) {
        count++;
        System.out.println(o.hasChanged());
        System.out.println(arg+""+count);
        ConcreteObservable o1 = (ConcreteObservable) o;
        if(o1.countObservers() >= count){
            o1.addNewValue("b");
        }
    }

}
